package com.dao.userdao;

import com.mapper.ArticleMapper;
import com.mapper.UserMapper;
import com.pojo.Article;
import com.pojo.Column;
import com.pojo.FansItem;
import com.pojo.SearchUser;
import com.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;
import java.util.List;

public class Search {
      /**
       *搜素用户
       */
      public static List<SearchUser> search_user(int page_number,String userid,String search_content) throws IOException {
            System.out.println("[info]搜索用户");
            //获取sqlSession对象
            SqlSession sqlSession= MybatisUtil.getSqlSession();
            //3.获取Mapper接口的代理对象
            UserMapper userMapper=sqlSession.getMapper(UserMapper.class);
            //4.执行方法
            List<SearchUser>searchUsers;
            searchUsers=userMapper.search_user(page_number,userid,search_content);
            //提交事务
            sqlSession.commit();
            //5.释放资源
            sqlSession.close();

            return searchUsers;
      }
      /**
       * 搜素博客
       */
      public static List<Article> search_blog(int page_number,String search_content)throws IOException{
            System.out.println("[info]搜索博客");
            //获取sqlSession对象
            SqlSession sqlSession= MybatisUtil.getSqlSession();
            //3.获取Mapper接口的代理对象
            ArticleMapper articleMapper=sqlSession.getMapper(ArticleMapper.class);
            //4.执行方法
            List<Article>articles;
            articles=articleMapper.search_blog(page_number, search_content);
            //提交事务
            sqlSession.commit();
            //5.释放资源
            sqlSession.close();

            return articles;
      }
      /**
       * 搜索专栏
       */
      public static List<Column> search_column(int page_number,String search_content)throws IOException{
            System.out.println("[info]搜索专栏");
            //获取sqlSession对象
            SqlSession sqlSession= MybatisUtil.getSqlSession();
            //3.获取Mapper接口的代理对象
            ArticleMapper articleMapper=sqlSession.getMapper(ArticleMapper.class);
            //4.执行方法
            List<Column>columns;
            columns=articleMapper.search_column(page_number, search_content);
            //提交事务
            sqlSession.commit();
            //5.释放资源
            sqlSession.close();

            return columns;
      }
}
